package chart;

import java.io.BufferedReader;
import java.io.FileReader;

import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;

public class resultChart {
	
	public static void main(String arg[]){
		 XYSeries series1 = new XYSeries("GamesWon");
		 XYSeries series2 = new XYSeries("Result");
		 
		
		    try {
		    	 BufferedReader br = new BufferedReader(new FileReader("results.txt"));
		        String line = br.readLine();
		        int game = 1;
		        int won = 0;
		        while (line != null) {
		            if( line.indexOf("true") != -1 )
		            {
		            	won++;
		            }
		            series1.add(game,(double)won/game);
		            
		            int space1 = line.indexOf(" ");
		            int space2 = line.indexOf(" ",space1+1);
		            String first = line.substring(0,space1);
		            String second = line.substring(space1+1,space2);
		            
		            series2.add(game,Integer.parseInt(first)-Integer.parseInt(second));
		            
		            line = br.readLine();
		            game++;
		        }
		        br.close();
		    } catch(Exception ex) {
		       ex.printStackTrace();
		    }
		 
		 
		 XYDataset xyDataset1 = new XYSeriesCollection(series1);
		 XYDataset xyDataset2 = new XYSeriesCollection(series2);
		 
		 JFreeChart chart1 = ChartFactory.createXYLineChart("GamesWon", "Episodes played", "Percentage of games won",
				 xyDataset1, PlotOrientation.VERTICAL, true, true, false);
		 ChartFrame frame1=new ChartFrame("Result Chart",chart1);
		 
		 JFreeChart chart2 = ChartFactory.createXYLineChart("Result", "Episodes played", "ownHealth - enemyHealth",
				 xyDataset2, PlotOrientation.VERTICAL, true, true, false);
		 ChartFrame frame2=new ChartFrame("Result Chart",chart2);
		 
		 
		 frame1.setSize(800,300);
		 frame1.setVisible(true);
		 
		 
		 frame2.setSize(800,300);
		 frame2.setVisible(true);
		 
		 
	}
}

